// subpage/pages/combo/combo.js
const app = getApp();
import service from '../../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    baseUrl: app.data.url,
    comboList:[],
    gaugeOption:{ //定义参数
      id: 'gaugeId0',
      value: 25.5,
      axisTickLength: 2//该属性与axisTick互斥，存在axisTickLength并大于0，axisTick就无效
    },
    ballInfo: {ballType:'all',ballSize:180,waveColor:'#ffffff',ballPadding:'0'},
    loadPercent: 40,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList()
  },
  getList (){
    let that = this
    let res = service('GET', '/combo/activity/all').then(result => {
      console.log('套餐',result)
      that.setData({
        comboList: result.data.list,
      })
    })
  },
  //购买
  goBuy(event){
    console.log('点击购买',event)
    wx.navigateTo({
      url: '/subpage/pages/combodetail/combodetail?id='+event.target.dataset.id,
    })
    let id = event.target.dataset.id
    let that = this
    let res = service('POST', '/combo/activity/buy',{
      id: id,
      force: false
    }).then(result => {
      console.log('套餐',result)
      if(result.data.code ==0){
        wx.showToast({
          title: '购买成功',
          icon: 'none'
        })
      }
      // that.setData({
      //   comboList: result.data.list,
      // })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})